package BookManage;

import java.sql.*;

public class selectBook {
    public static void main(String[] args) {
        Connection connection=null;
        PreparedStatement statement=null;
        ResultSet resultSet=null;
        try {
            connection=operation.My_Get_Connection();
            String sql="select b.name book_name,b.author book_author,"+
                    "s.name student_name,bi.start_time,bi.end_time from"+
                    "borrow_info bi join book b on bi.book_id=b.id"+
                    "join category c on b.category_id=c.id"+
                    "join student s on b.student_id=s.id"+
                    "where c.name=?";
            statement=connection.prepareStatement(sql);
            statement.setString(1,"计算机");
            resultSet=statement.executeQuery();
            while (resultSet.next()){
                String bookName=resultSet.getString("book_name");
                String bookAuthor=resultSet.getString("book_author");
                String studentName=resultSet.getString("student_name");
                Timestamp startTime=resultSet.getTimestamp("start_Time");
                Timestamp endTime=resultSet.getTimestamp("end_time");
                System.out.println(String.format("书名：%s,作者: %s,借阅者: %s,借阅起始时间: %s,借阅结束时间: %s",bookName,bookAuthor,studentName,startTime,endTime));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            operation.My_close(connection,statement,resultSet);
        }
    }
}
